#include <iostream>
using namespace std;

class Array
{
public:
    // 构造函数
    Array(int count) {
        this->count = count;
        Arr = new int[count];
        cout << "Array()" << endl;
    }
    // 拷贝构造函数
    Array(const Array & arr) {
        // 浅拷贝
        //this->count = arr.count;
        //this->Arr = arr.Arr;
        cout << "Array(const Array & arr)" << endl;
        // 浅拷贝
        this->count = arr.count;
        // 深拷贝正确用法
        this->Arr = new int[count];
        for (int i = 0; i < count; i++) {
            this->Arr[i] = arr.Arr[i];
        }
    }
    // 移动构造函数
    Array(const Array && arr) : count(arr.count), Arr(arr.Arr) {
        arr.Arr = nullptr;
    }
    // 移动赋值
    Array& operator=(Array &&arr) {
        delete [] Arr;
        Arr = arr.Arr;
        count = arr.count;
        delete [] arr.Arr;
        arr.Arr = nullptr;
        return *this;
    }
    // 析构函数
    ~Array() {
        delete [] Arr;
        Arr = nullptr;
        cout << "~Array(): " << count << endl;
    }
    void printAddress() {
        cout << "address: " << Arr << endl;
    }
    void setCount(int count) { this->count = count; }
    int getCount() { return count; }
private:
    int count;
    int *Arr;
};

void stackInstantiation()
{
    Array arr1(5);
    Array arr2 = arr1;
    arr1.printAddress();
    arr2.printAddress();
}

int main()
{
    stackInstantiation();
    return 0;
}
